extends CenterContainer


var edit_data = null

onready var coin_type = $PanelContainer/VBoxContainer/coinType/OptionButton
onready var coin_num  = $PanelContainer/VBoxContainer/coinNum/SpinBox

signal close


func set_edit_data(data):
	self.edit_data = data
	
	if edit_data:
		coin_type.select(data.get("coinType",1) - 1)
		coin_num.value = int(data.get("coinNum",1))

func _on_cancel_button_up():
	MainTool.getUILayer().pop_ui()


func _on_ok_button_up():
	if edit_data:
		edit_data["coinType"] = coin_type.get_selected_id()
		edit_data["coinNum"] = coin_num.value
		DataSource.update_data(DataSource.coin_consume, edit_data)
		MainTool.toast_info("更新成功!")
	else:
		var data = {
			"coinType": coin_type.get_selected_id(),
			"coinNum": coin_num.value
		}
		var list = DataSource.get_data_list(DataSource.coin_consume)
		for item in list:
			if item["coinType"] == data["coinType"] and item["coinNum"] == data["coinNum"]:
				MainTool.toast_info("不能重复添加!")
				return
		DataSource.add_data(DataSource.coin_consume, data)
	
		MainTool.toast_info("添加成功!")
	
	MainTool.getUILayer().pop_ui()
	
	emit_signal("close")
